import { defineStore } from 'pinia'
import { getCompanyInfo , updateCompanyInfo } from '@/api/boss/index'



export const useBossStore = defineStore('boss', () => {
    //存储boss的信息
    const boss: any = reactive({})
    const signType: any = ref('')
    function getBossInfo() {
      return new Promise((resolve, reject) => {
        getCompanyInfo().then(res => {
            //存储一份信息放到boss中
        console.log(res.data.msg)
        let{data:{code,data}}=res
        if(code!==200){
            return
        }else{
            //存储信息
            Object.assign(boss,data)
            resolve(data)
        }
        }).catch(err => {
          reject(err)
        })
      })
    }

    function updateBossInfo(data: any) {
      return new Promise((_, reject) => {
        updateCompanyInfo(data).then(res => {
        console.log(res.data.msg)
        let{data:{code}}=res
        if(code!==200){
          console.log('更新失败');
            return
        }
        }).catch(err => {
          reject(err)
        })
      })
    }

    return {
        boss,
        signType,
        getBossInfo,
        updateBossInfo
    }   
})  

